t = int(input())
while t != 0:
t -= 1
n, m = map(int, input().split())
v = []
for i in range(n):
a = list(map(int, input().split()))
for j in a:
v.append(j)
idx = 0
for i in range(n * m):
if v[i] > v[idx]:
idx = i
x = idx // m
y = idx % m
print(max(x + 1, n - x) * max(y + 1, m - y))
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, false, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define mod 1000000007
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
{
ll int n, m, ma=-1000000000, p, q;
cin>>n>>m;
ll int a[n][m];
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
cin>>a[i][j];
ma=max(a[i][j],ma);
}
}
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
if(a[i][j]==ma){
p=i;
q=j;
break;
}
}
}
//cout<<p<<" "<<q<<endl;
cout<<max(p+1,n-p)*max(q+1, m-q)<<endl;
}
return 0;
}
409H - A + B Strikes Back | 1262A - Math Problem |
158C - Cd and pwd commands | 194A - Exams |
1673B - A Perfectly Balanced String | 1104B - Game with string |
1169B - Pairs | 1567D - Expression Evaluation Error |
78A - Haiku | 1287A - Angry Students |
1428A - Box is Pull | 234B - Reading |
581B - Luxurious Houses | 1481C - Fence Painting |
935A - Fafa and his Company | 22A - Second Order Statistics |
1720B - Interesting Sum | 1720A - Burenka Plays with Fractions |
3A - Shortest path of the king | 1720C - Corners |
574A - Bear and Elections | 352B - Jeff and Periods |
1244A - Pens and Pencils | 1670A - Prof Slim |
1189A - Keanu Reeves | 678A - Johny Likes Numbers |
1699C - The Third Problem | 1697D - Guess The String |
754B - Ilya and tic-tac-toe game | 760A - Petr and a calendar |